<?php
class UserIdentity extends CUserIdentity{
    private $_id;
    public function authenticate() 
    {
        //parent::authenticate();
        $user = User::model()->findByAttributes(array('username'=>$this->username));
        if($user===NULL){
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        }else if($user->password!==$this->password){
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        }else{
            $this->_id=$user->id;
            $this->setState('logined', $user);
            $this->errorCode = self::ERROR_NONE;
        }
        return $this->errorCode==self::ERROR_NONE;
    }

    public function getId() {
        parent::getId();
        return $this->_id;
    }
}
